package Semaphore;

import java.util.concurrent.Semaphore;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(4);
        //P操作，申请资源；类似停车场停车，本来有4个空位，
        // acquire相当于申请空位，于是空位就少一个(count--)
        semaphore.acquire();
        System.out.println("P处理");
        semaphore.acquire();
        System.out.println("P处理");
        semaphore.acquire();
        System.out.println("P处理");
        semaphore.acquire();
        System.out.println("P处理");
        semaphore.acquire();
        System.out.println("P处理");
        //V操作，空位让出一个(count++)
        semaphore.release();
    }
}
